<template>
    <div>
        <el-dialog title="test" :visible.sync="dialog" width="450px" :close-on-click-modal="false" top="50px">
            <p class="top-tip fc-theme">这是个例子</p>
            <el-form ref="form" :model="form" label-width="80px" class="bind-phone">
                <el-form-item label="充值金额：" label-width="150px" >
                    <el-input v-model="form.amount" placeholder="请输入充值金额"> </el-input>
                </el-form-item>
                <el-form-item label="充值订单号：" label-width="150px">
                    <el-input placeholder="请输入订单号" @keyup.enter.native="handleSubmit" v-model="form.trade_sn"></el-input>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer text-center">
                <el-button @click="dialog = false">取 消</el-button>
                <el-button type="danger" @click="handleSubmit">确 定</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
export default {
    props: {
        value: {
            type: Boolean,
            default: true
        },
        exampleData: {
            type: Object,
            default: {}
        }
    },
    data() {
        return {
            dialog: !!this.value,
            form: {
                amount: '',
                trade_sn: ''
            }
        }
    },
    methods: {
        async handleSubmit() {
            const data = await this.$fetch('/recharge_query', {...this.form})
            if (data.status === 0) {
                this.$message.success('提交成功')
                this.$emit('success')
                this.dialog = false
            }
        }
    },
    watch: {
        dialog(val) {
            if (!val) this.$emit('input', val)
        }
    }
}
</script>

<style lang="scss" scoped>
.top-tip {
    margin-top: -20px;
    margin-bottom: 20px;
}
</style>